package com.bigdata.controller;

import com.bigdata.pojo.Resume;
import com.bigdata.service.IResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.List;

@Controller
@RequestMapping("/resume")
public class ResumeController {


    @Autowired
    private IResumeService resumeService;

    @RequestMapping("/login")
    public String  login(String username, String password, RedirectAttributes redirectAttributes){
        System.out.println(username+"  --"+password);

        return "redirect:findAll";
    }

    @RequestMapping("/findAll")
    @ResponseBody
    public ModelAndView findAll(ModelAndView modelAndView){

        List<Resume> resumeList=resumeService.findAll();
        System.out.println("findAll:"+resumeList);
        modelAndView.addObject(resumeList);
        modelAndView.setViewName("resumeList");
       return modelAndView;

    }

    @RequestMapping("/editById")
    public ModelAndView editById(Long id,ModelAndView modelAndView){

       Resume  resume= resumeService.findById(id);

        modelAndView.addObject(resume);
        modelAndView.setViewName("editResult");
       return modelAndView;

    }

    @RequestMapping("/toSave")
    public String toSave(){

       return "save";

    }
    @RequestMapping("/toLogin")
    public String toLogin(){

       return "login";

    }

    @RequestMapping("/update")
    public String update(Resume resume){
        resumeService.updateById(resume);
       return "redirect:findAll";

    }
    @RequestMapping("/deleteById")
    public String deleteById(Long id){
        resumeService.deleteById(id);
       return "redirect:findAll";
    }
    @RequestMapping("/save")
    public String save(Resume resume){
        resumeService.save(resume);
       return "redirect:findAll";
    }




}
